# podspecs 上传

#当前需要更新的版本

version='1.0.0'

function update_podspecs() {
local podspecs
podspecs=$(echo "$@")
result=1
for podspec in ${podspecs[@]};do
echo ""
echo -e "\033[01;34m**正在上传 ${podspec}.podspec **\033[0m"
echo ""
pod repo push LGHSpecs ${podspec}.podspec --use-libraries --allow-warnings --skip-import-validation

if [ $? -ne 0 ]; then
echo ""
echo -e "\033[01;34m**${podspec}.podspec上传失败**\033[0m"
echo ""
result=0
break
else
echo -e "\033[01;34m**${podspec}.podspec上传成功**\033[0m"
fi
done
#判断是否都上传成功
if [ $result -ne 0 ]; then
echo ""
echo -e "\033[01;34m**SUCCESS**\033[0m"
echo ""
else
echo ""
echo -e "\033[01;34m**FAIL**\033[0m"
echo ""
fi
}

function update_tag() {
echo -e "\033[01;31m正在检查tag列表\033[0m"
git fetch
git tag --list | grep -e ${version}$
if [ $? -eq 0 ];then
echo ""
echo -e "\033[01;31m检测到当前tag已经标记，是否删除重新标记(y/n)\033[0m"
echo ""
#获取用户操作
read num
if [ ${num} == 'y' ];then
git tag --delete $version
git push origin :refs/tags/$version
echo "结果"
echo $?
git tag ${version}
echo "结果"
echo $?
else
echo ""
echo -e "\033[01;34m 终止上传 \033[0m"
echo ""
fi
else
git tag $version
fi
return $?
}

#开始
echo -e "\033[01;31m正在push...\033[0m"
git push
# 设置tag
update_tag
echo $?
#判断tag是否操作成功
if [ $? -nq 0 ]; then
echo ""
echo -e "\033[01;34m**tag标志失败 $version**\033[0m"
echo ""
echo -e "\033[01;34m 终止上传 \033[0m"
echo ""
exit 1
else
echo -e "\033[01;34m**tag标志成功 $version**\033[0m"
echo -e "\033[01;31m正在上传tags\033[0m"
git push --tags

update_podspecs LGHKitModule
fi


